package com.sstir.doctor.controller;

import com.sstir.doctor.pojo.bo.RankingListBO;
import com.sstir.doctor.pojo.vo.QuestionVO;
import com.sstir.doctor.pojo.vo.RankingListVO;
import com.sstir.doctor.pojo.vo.UserScoreVO;
import com.sstir.doctor.result.RespResult;
import com.sstir.doctor.service.IQueListService;
import com.sstir.doctor.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName GameController
 * @Description
 * @Author hanjunjun
 * @Date 2021/1/14 18:21
 */
@RestController
@RequestMapping("/game")
@Slf4j
@CrossOrigin
@Api(tags = "GameController")
public class GameController {

    @Autowired
    private IUserInfoService userInfoService;

    @Autowired
    private IQueListService queListService;

    @GetMapping("/registerUsername")
    @ApiOperation("用户填写用户名，判重")
    public RespResult registerUsername(@RequestParam("username") String username){
        return userInfoService.registerUsername(username);
    }

    @PostMapping("/getRankingList")
    @ApiOperation(value = "获取分数排行榜", response = RankingListVO.class)
    public RespResult getRankingList(@RequestBody @Validated RankingListBO rankingListBO){
        return userInfoService.getRankingList(rankingListBO);
    }

    @PostMapping("/submitCore")
    @ApiOperation("提交用户成绩")
    public RespResult submitCore(@RequestBody @Validated UserScoreVO userScoreVO){
        return userInfoService.submitCore(userScoreVO);
    }

    @GetMapping("/getQuestion")
    @ApiOperation(value = "随机获取n个问题", response = QuestionVO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "quesCount", value = "获取的问题个数", example = "3", paramType = "query", required = true),
            @ApiImplicitParam(name = "existQueIds", value = "已经答过的问题id,多个以,分隔", paramType = "query", dataType = "String")
    })
    public RespResult getQuestion(@RequestParam(value = "quesCount", defaultValue = "3") Integer quesCount,
                                  @RequestParam(value = "existQueIds", required = false) String existQueIds){
        return queListService.getQuestion(quesCount, existQueIds);
    }



}
